package org.ihelpuoo.io;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FilePatternFilter implements FilenameFilter, FileFilter
{
	public static FilePatternFilter getInstance(String s)
	{
		if (null == s)
			return null;
		return new FilePatternFilter(Pattern.compile(s,Pattern.CASE_INSENSITIVE));
	}

	private Pattern	pattern;

	private FilePatternFilter(Pattern pattern)
	{
		this.pattern = pattern;
	}

	public boolean accept(File dir, String name)
	{
		Matcher matcher = pattern.matcher(name);
		return matcher.matches();
	}

	public boolean accept(File pathname)
	{
		Matcher matcher = pattern.matcher(pathname.getPath());
		return matcher.matches();
	}

}
